package com.dxf.sysadmin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dxf.common.utils.ResultJson;
import com.dxf.sysadmin.entity.Clazz;
import com.dxf.sysadmin.entity.SysUser;
import com.dxf.sysadmin.entity.qo.ClazzQo;
import com.dxf.sysadmin.mapper.ClazzMapper;
import com.dxf.sysadmin.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 班级表 服务实现类
 */
@Slf4j
@Service
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz> implements ClazzService {

    /**
     *班级列表分页查询
     */
    @Override
    public ResultJson clazzPage(ClazzQo qry) {
        Page<Clazz> clazzPage = new Page<>(qry.getPage(), qry.getLimit());

        IPage<Clazz> userIPage = page(clazzPage);
        Map<String, Object> map = new HashMap<>();
        map.put("rows",userIPage.getRecords());
        map.put("total",userIPage.getTotal());
        return ResultJson.ok().data(map);
    }

    /**
     *更具id列表删除班级
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ResultJson deleteClazz(List<Long> list) {
        removeByIds(list);
        //TODO
        return ResultJson.ok();
    }

    /**
     *新增或者更新班级
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ResultJson saveOrUpdateClazz(Clazz clazz) {
        saveOrUpdate(clazz);
        return ResultJson.ok();
    }

}
